import json

from django.http import HttpResponse, JsonResponse
from django.shortcuts import render

# Create your views here.
from django.views import View


class ResponseView(View):
    def get(self, request):
        # return HttpResponse(content='response', content_type='application/json',status=200)

        # response = HttpResponse()
        # response.content = '响应的对象的属性'
        # response.status_code = 333
        #
        # return response

        # 子类 JsonResponse()
        #  1. json.dumps(data_dict)  2.content_type='application/json'
        data_dict = {
            'name': "laowang",
            "age": 18
        }
        # data_str = json.dumps(data_dict)
        # response = HttpResponse(data_str, content_type='application/json')
        # return response

        return JsonResponse(data_dict)
